/* Copyright (C)
 * 2017 - Xianlee.Wu  xianleewu@163.com
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

#include "stdio.h"
#include "stdlib.h"
#include "audiochat.h"
#include "wifiap.h"

#define MEDIA_STREAMER  "mediastream"
#define MEDIA_RECIEVER  "vlc"
#define CMD_MAX_LEN     128

#define MEDIA_STREAMER_CMD \
    "mediastream --local %d --remote %s:%d --payload %s --bitrate %d &"

#define MEDIA_RECIEVER_CMD \
    "vlc -f rtsp://%s:%s:%s &"

int start_audio_chat(int local_port, const char* remote_ip, int remote_port,
                     const char* payload, int bitrate)
{
    char cmd_str[CMD_MAX_LEN] = {0};

    snprintf(cmd_str, CMD_MAX_LEN, MEDIA_STREAMER_CMD, local_port, remote_ip,
             remote_port, payload, bitrate);

    runapp(cmd_str);

    return 0;
}

int start_video_reciever(const char* remote_ip, const char* name, const char* pwd)
{
    char cmd_str[CMD_MAX_LEN] = {0};

    snprintf(cmd_str, CMD_MAX_LEN, MEDIA_RECIEVER_CMD, name, pwd, remote_ip);

    runapp(cmd_str);

    return 0;
}
